package charstream;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Demo1 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s ="黑马程序员";
        //用idea默认UTF-8将中文编码为一系列字节
        byte[] bytes = s.getBytes();
        //Arrays.toString工具类  打印它的属性值，而不是地址值
        System.out.println(Arrays.toString(bytes));
        //指定的码表
        byte [] bytes1 = s.getBytes("GBK");
        System.out.println(Arrays.toString(bytes1));
        //解码默认UTF-8
        byte [] bytes2 ={-23, -69, -111, -23, -87, -84, -25, -88, -117, -27, -70, -113, -27, -111, -104};
        //指定GBK
        byte [] bytes3 ={-70, -38, -62, -19, -77, -52, -48, -14, -44, -79};
        String s1 = new String(bytes2);
        System.out.println(s1);
        String s2 = new String(bytes3,"gbk");
        System.out.println(s2);
    }
}
